package com.xlh.extended;

import com.xlh.api.Dictionary;
import lombok.extern.slf4j.Slf4j;
import ro.fortsoft.pf4j.Extension;
import ro.fortsoft.pf4j.Plugin;
import ro.fortsoft.pf4j.PluginException;
import ro.fortsoft.pf4j.PluginWrapper;

import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @author xulihua
 * @date 2021/9/26 14:57
 */
@Slf4j
public class ExtendedPlugin extends Plugin {

    public ExtendedPlugin(PluginWrapper wrapper) {
        super(wrapper);
    }

    @Override
    public void start() throws PluginException {
        log.info("ExtendedPlugin start....");
        super.start();
    }

    @Override
    public void stop() throws PluginException {
        log.info("ExtendedPlugin stop....");
        super.stop();
    }

    @Extension
    public static class ExtendedDictionary implements Dictionary {
        /**
         * 字典存储的内容
         */
        private final SortedMap<String, String> map = new TreeMap<>();

        /**
         * 构造时即创建字典内容
         */
        public ExtendedDictionary() {
            this.map.put("xml", "a document standard often used in web services, among other things");
            this.map.put("REST", "an architecture style for creating, reading, updating, and deleting data that attempts to use the common vocabulary of the HTTP protocol; Representational State Transfer");
        }

        @Override
        public String getDefinition(String word) {
            return map.get(word);
        }
    }
}
